<?php
namespace app\admin\controller;

use app\admin\api\ConferenceMember;
use app\admin\controller\Permissions;


/**
 * 会议站--站点会员管理
 */
class Confermember extends  Permissions{

    /**
     * 获取站点会员列表
     */
    public function list($sid){

        //换区网站token
        $token = getapptoken($sid);

        $data = new ConferenceMember();

        //接收数据
        if($this->request->isPost()){

            $post = $this->request->post();
            $res = $data->memberList($token,$post);

            $site = $res->items;

            if(empty($site)){
                $this->assign('intrs',-1);
                $this->assign('sid',$sid);
            }else{
                $intrs[0]['intr'] = $site;
                $intrs[0]['sid'] = $sid;
                return json($intrs);
            }
        }else{
            $fy['page'] = 1;
            $fy['limit'] = 10;

            $res = $data->memberList($token,$fy);
            $site = $res->items;

            if(empty($site)){
                $this->assign('intrs',-1);
                $intrs[0]['sid'] = $sid;
            }else{

                //列表总数
                $total = $res->meta->total;
                $intrs[0]['intr'] = $site;
                $intrs[0]['sid'] = $sid;

                $this->assign('sid',$sid);
                $this->assign('intrs',$intrs);
                $this->assign('total',$total);
            }
            return view();

//            var_dump($site);
        }
    }

    /**
     * 获取会员详情
     * @return [type] [description]
     */
    public function details($id,$sid){

        //换取网站token
        $token = getapptoken($sid);

        $data = new ConferenceMember();
        $res = $data->memberDetails($id,$token);

        //获取站点语言
        $lang = getlang($sid);

        $this->assign('sid',$sid);
        $this->assign('lang',$lang);
        $this->assign('intr',$res);


        return view();
    }

    /**
     * 删除会员
     */
    public function delete(){
        if ($this->request->isPost()) {

            //接收数据
            $post = $this->request->post();
            $id = $post['id'];
            $sid = $post['sid'];

            //换区网站token
            $token = getapptoken($sid);

            //请求接口
            $data = new ConferenceMember();
            $res = $data->memberDelete($id,$token);

            if ($res == 555) {
                $this->success("删除成功");

            } else {
                $this->error("$res");
            }
        }
    }


}